<template>
  <div class="banner-wrapper">
    <div class="banner">
      <el-carousel height="400px" :interval="3000" arrow="always">
        <el-carousel-item v-for="item in banners" :key="item.id" @click="handleClick(item)">
          <div class="banner-content" :style="{ backgroundImage: `url(${item.imageUrl})` }">
            <div class="banner-info">
              <h2>{{ item.title }}</h2>
              <p>今日上线</p>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    
    <div class="category-tabs">
      <div class="tab-item">
        <el-icon><Star /></el-icon>
        <span>大家在听</span>
      </div>
      <div class="tab-item">
        <el-icon><Headset /></el-icon>
        <span>猜你喜欢</span>
      </div>
      <div class="tab-item">
        <el-icon><VideoPlay /></el-icon>
        <span>新歌速递</span>
      </div>
      <div class="tab-item">
        <el-icon><TrendCharts /></el-icon>
        <span>排行榜单</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { commonAPI } from '@/api'
import type { BannerInfo } from '@/types'

const router = useRouter()
const banners = ref<BannerInfo[]>([])

const handleClick = (banner: BannerInfo) => {
  if (banner.targetId) {
    switch (banner.targetType) {
      case 1: // 歌曲
        router.push(`/song/${banner.targetId}`)
        break
      case 2: // 歌单
        router.push(`/playlist/${banner.targetId}`)
        break
      case 3: // 专辑
        router.push(`/album/${banner.targetId}`)
        break
    }
  }
}

onMounted(async () => {
  try {
    const res = await commonAPI.getBanners()
    banners.value = res.data
  } catch (error) {
    console.error('Failed to load banners:', error)
  }
})
</script>

<style scoped lang="scss">
.banner-wrapper {
  position: relative;
  background: linear-gradient(to bottom, #000, transparent);
  
  .banner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    
    :deep(.el-carousel__item) {
      cursor: pointer;
      
      .banner-content {
        height: 100%;
        background-size: cover;
        background-position: center;
        display: flex;
        align-items: flex-end;
        padding: 40px;
        
        .banner-info {
          color: white;
          text-shadow: 0 1px 2px rgba(0,0,0,0.5);
          
          h2 {
            font-size: 32px;
            margin-bottom: 10px;
          }
          
          p {
            font-size: 16px;
            opacity: 0.8;
          }
        }
      }
    }
  }
  
  .category-tabs {
    max-width: 800px;
    margin: -30px auto 0;
    background: white;
    border-radius: 8px;
    padding: 20px;
    display: flex;
    justify-content: space-around;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
    
    .tab-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      cursor: pointer;
      
      .el-icon {
        font-size: 24px;
        color: $primary-color;
      }
      
      span {
        font-size: 14px;
      }
      
      &:hover {
        color: $primary-color;
      }
    }
  }
}
</style> 